package org.zz.tool;

import java.util.Vector;

public class zzStringTrans {
    public zzStringTrans() {
    }

    public static Vector<Byte> str2vectorbcd(String str) {
        byte[] a = str.getBytes();
        Vector v = new Vector();
        v.clear();

        for(int i = 0; i < str.length() / 2; ++i) {
            byte b = (byte)(a[2 * i] - 48 << 4 | a[2 * i + 1] - 48);
            v.add(Byte.valueOf(b));
        }

        return v;
    }

    public static byte[] str2bcd(String str) {
        byte[] a = str.getBytes();
        Vector v = new Vector();
        v.clear();

        for(int tmpbt = 0; tmpbt < str.length() / 2; ++tmpbt) {
            byte j = (byte)(a[2 * tmpbt] - 48 << 4 | a[2 * tmpbt + 1] - 48);
            v.add(Byte.valueOf(j));
        }

        byte[] var5 = new byte[v.size()];

        for(int var6 = 0; var6 < v.size(); ++var6) {
            var5[var6] = ((Byte)v.get(var6)).byteValue();
        }

        return var5;
    }

    public static Vector<Byte> datetime2vectorbcd(String time) {
        String[] a = time.split(" ");
        time = a[0] + a[1];
        a = time.split("[:-]");
        StringBuilder b = new StringBuilder();
        String[] var6 = a;
        int var5 = a.length;

        for(int var4 = 0; var4 < var5; ++var4) {
            String s = var6[var4];
            b.append(s);
        }

        time = b.toString().substring(2);
        return str2vectorbcd(time);
    }

    public static byte[] datetime2bcd(String time) {
        String[] a = time.split(" ");
        time = a[0] + a[1];
        a = time.split("[:-]");
        StringBuilder b = new StringBuilder();
        String[] var6 = a;
        int var5 = a.length;

        for(int var4 = 0; var4 < var5; ++var4) {
            String s = var6[var4];
            b.append(s);
        }

        time = b.toString().substring(2);
        return str2bcd(time);
    }

    public static byte[] time2bcd(String time) {
        return str2bcd(time);
    }

    public static String bcd2time(byte[] time) {
        int hour = (time[0] >> 4) * 10 + (time[0] & 15);
        int min = (time[1] >> 4) * 10 + (time[1] & 15);
        int sec = (time[2] >> 4) * 10 + (time[2] & 15);
        return String.format("%02d:%02d:%02d", new Object[]{Integer.valueOf(hour), Integer.valueOf(min), Integer.valueOf(sec)});
    }

    public static String bcd2date(byte[] date) {
        int year = 2000 + 10 * (date[0] >> 4) + (date[0] & 15);
        int mon = 10 * (date[1] >> 4) + (date[1] & 15);
        int day = 10 * (date[2] >> 4) + (date[2] & 15);
        return String.format("%02d-%02d-%02d", new Object[]{Integer.valueOf(year), Integer.valueOf(mon), Integer.valueOf(day)});
    }

    public static String bcd2datetime(byte[] datetime) {
        int year = 2000 + 10 * (datetime[0] >> 4) + (datetime[0] & 15);
        int mon = 10 * (datetime[1] >> 4) + (datetime[1] & 15);
        int day = 10 * (datetime[2] >> 4) + (datetime[2] & 15);
        int hour = (datetime[3] >> 4) * 10 + (datetime[3] & 15);
        int min = (datetime[4] >> 4) * 10 + (datetime[4] & 15);
        int sec = (datetime[5] >> 4) * 10 + (datetime[5] & 15);
        return String.format("%02d-%02d-%02d %02d:%02d:%02d", new Object[]{Integer.valueOf(year), Integer.valueOf(mon), Integer.valueOf(day), Integer.valueOf(hour), Integer.valueOf(min), Integer.valueOf(sec)});
    }

    public static String bcd2str(byte[] bcd) {
        StringBuilder sb = new StringBuilder();
        byte[] var5 = bcd;
        int var4 = bcd.length;

        for(int var3 = 0; var3 < var4; ++var3) {
            byte b = var5[var3];
            sb.append(String.format("%d%d", new Object[]{Integer.valueOf(b >> 4), Integer.valueOf(b & 15)}));
        }

        return sb.toString();
    }

    public static String hex2str(byte[] hex) {
        StringBuilder sb = new StringBuilder();
        byte[] var5 = hex;
        int var4 = hex.length;

        for(int var3 = 0; var3 < var4; ++var3) {
            byte b = var5[var3];
            sb.append(String.format("%02x", new Object[]{Byte.valueOf(b)}));
        }

        return sb.toString();
    }

    public static byte[] str2hex(String str) {
        byte[] a = str.getBytes();
        Vector v = new Vector();
        v.clear();

        for(int tmpbt = 0; tmpbt < str.length() / 2; ++tmpbt) {
            byte j;
            if(48 <= a[2 * tmpbt] && a[2 * tmpbt] <= 57) {
                j = (byte)(a[2 * tmpbt] - 48);
            } else if(65 <= a[2 * tmpbt] && a[2 * tmpbt] <= 70) {
                j = (byte)(a[2 * tmpbt] - 65 + 10);
            } else {
                j = (byte)(a[2 * tmpbt] - 97 + 10);
            }

            byte b2;
            if(48 <= a[2 * tmpbt + 1] && a[2 * tmpbt + 1] <= 57) {
                b2 = (byte)(a[2 * tmpbt + 1] - 48);
            } else if(65 <= a[2 * tmpbt + 1] && a[2 * tmpbt + 1] <= 70) {
                b2 = (byte)(a[2 * tmpbt + 1] - 65 + 10);
            } else {
                b2 = (byte)(a[2 * tmpbt + 1] - 97 + 10);
            }

            byte b = (byte)(j << 4 | b2);
            v.add(Byte.valueOf(b));
        }

        byte[] var7 = new byte[v.size()];

        for(int var8 = 0; var8 < v.size(); ++var8) {
            var7[var8] = ((Byte)v.get(var8)).byteValue();
        }

        return var7;
    }
}
